// 状态：active(在用) / idle(闲置) / stopped(停用)
const depts = ['制造一部', '制造二部', '总装线', '质检部', '工艺部']

function rand(arr) { return arr[Math.floor(Math.random() * arr.length)] }
function randInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min }
function todayAt(h, m = 0) {
  const d = new Date()
  d.setHours(h, m, 0, 0)
  return d.toISOString()
}
function daysAgo(n) {
  const d = new Date()
  d.setDate(d.getDate() - n)
  d.setHours(0, 0, 0, 0)
  return d.toISOString()
}

export const mockUsageItems = [
  {
    id: 1,
    assetName: '自动化控制单元',
    enabledAt: daysAgo(320),
    department: rand(depts),
    useRange: { start: todayAt(8), end: todayAt(17, 30) },
    idleRange: { start: todayAt(12), end: todayAt(13) },
    stopAt: null,
    status: 'active'
  },
  // {
  //   id: 2,
  //   assetName: '上冲机构',
  //   enabledAt: daysAgo(590),
  //   department: rand(depts),
  //   useRange: { start: todayAt(9), end: todayAt(18) },
  //   idleRange: null,
  //   stopAt: null,
  //   status: 'idle'
  // },
  // {
  //   id: 3,
  //   assetName: '上冲杆',
  //   enabledAt: daysAgo(1200),
  //   department: rand(depts),
  //   useRange: null,
  //   idleRange: null,
  //   stopAt: daysAgo(10),
  //   status: 'stopped'
  // },
  // {
  //   id: 4,
  //   assetName: '冷干系统',
  //   enabledAt: daysAgo(60),
  //   department: rand(depts),
  //   useRange: { start: todayAt(7, 30), end: todayAt(16) },
  //   idleRange: { start: todayAt(10), end: todayAt(10, 20) },
  //   stopAt: null,
  //   status: 'active'
  // }
]

// 可生成更多
export function genUsage(n = 8) {
  const list = []
  for (let i = 1; i <= n; i++) {
    const status = ['active', 'idle', 'stopped'][randInt(0, 2)]
    list.push({
      id: i,
      assetName: `设备-${i}`,
      enabledAt: daysAgo(randInt(30, 1200)),
      department: rand(depts),
      useRange: status !== 'stopped' ? { start: todayAt(randInt(7, 10)), end: todayAt(randInt(16, 19)) } : null,
      idleRange: Math.random() > 0.6 ? { start: todayAt(12), end: todayAt(13) } : null,
      stopAt: status === 'stopped' ? daysAgo(randInt(1, 30)) : null,
      status
    })
  }
  return list
}
